package com.shanzhu.flower.dao;

import com.shanzhu.flower.entity.Announcement;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * 公告DAO接口
 */
@Repository
public interface AnnouncementDao {
    
    /**
     * 查询所有启用的公告
     */
    @Select("select * from announcements where status = 1 order by create_time desc")
    List<Announcement> selectEnabledAnnouncements();
    
    /**
     * 查询所有公告（管理员用）
     */
    @Select("select * from announcements order by create_time desc")
    List<Announcement> selectAllAnnouncements();
    
    /**
     * 根据ID查询公告
     */
    @Select("select * from announcements where id = #{id}")
    Announcement selectById(@Param("id") Integer id);
    
    /**
     * 新增公告
     */
    @Insert("insert into announcements(title, content, status, create_user) values(#{title}, #{content}, #{status}, #{createUser})")
    int insert(Announcement announcement);
    
    /**
     * 更新公告
     */
    @Update("update announcements set title = #{title}, content = #{content}, status = #{status} where id = #{id}")
    int update(Announcement announcement);
    
    /**
     * 删除公告
     */
    @Delete("delete from announcements where id = #{id}")
    int deleteById(@Param("id") Integer id);
    
    /**
     * 更新公告状态
     */
    @Update("update announcements set status = #{status} where id = #{id}")
    int updateStatus(@Param("id") Integer id, @Param("status") Integer status);
} 